package com.mall.goods.service.impl;

import com.mall.goods.model.CategoryBrand;
import com.mall.goods.mapper.CategoryBrandMapper;
import com.mall.goods.service.ICategoryBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 品牌分类关联表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-18
 */
@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand> implements ICategoryBrandService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addCategoryBrand(CategoryBrand categorybrand){
        return super.save(categorybrand);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(Integer categoryId){
        return super.removeById(categoryId);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateCategoryBrand(CategoryBrand categorybrand){
        return super.updateById(categorybrand);
    }

    @Override
    public CategoryBrand getById(Integer categoryId){
        return super.getById(categoryId);
    }

    @Override
    public List<CategoryBrand> selectList(CategoryBrand categorybrand){
        return super.list(getQueryWrapper(categorybrand));
    }

    @Override
    public Page<CategoryBrand> selectPage(Page<CategoryBrand> page, CategoryBrand categorybrand){
        return super.page(page, getQueryWrapper(categorybrand));
    }

    public LambdaQueryWrapper<CategoryBrand> getQueryWrapper(CategoryBrand categorybrand){
        return Wrappers.<CategoryBrand>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(categorybrand.getCategoryId()), CategoryBrand::getCategoryId, categorybrand.getCategoryId())
            .eq(ObjectUtils.isNotEmpty(categorybrand.getBrandId()), CategoryBrand::getBrandId, categorybrand.getBrandId())
        ;
    }
}
